package com.sikadwafastdaisfondturbo.pretloan.analysis

import com.sikadwa.analysis.AnalysisBuilder
import com.sikadwa.analysis.AnalyticsUtil
import com.sikadwa.syc.data.ASSycBuilder
import com.sikadwa.syc.data.ASSycManager
import com.sikadwafastdaisfondturbo.pretloan.base.BaseApp
import com.sikadwafastdaisfondturbo.pretloan.utils.config.Configs
import com.sikadwafastdaisfondturbo.pretloan.utils.http.AppUrls


/**
 * TODO: Analysis Lib 初始化时机
 */
object TestAnalysisInit {

    /**
     * TODO: APP启动时，初始化一下 analysis lib
     */
    fun initAnalysisLibAtAppLaunch() {
        AnalysisBuilder.product = Configs.AppName
        AnalysisBuilder.appVersion = "1"
        AnalysisBuilder.appPckName = "com.sikadwafastdaisfondturbo.pretloan"

        AnalysisBuilder.aesKey = "IWyKojGMVFszL5f2"
        AnalysisBuilder.aesIv = "4WaIMtGiLY9cDwWl"

        AnalysisBuilder.host = AppUrls.APP_URL
        AnalysisBuilder.zone = ""
        AnalysisBuilder.pathCommon = "/yQ4tnes08gUZz7zBwXLFw"

        AnalysisBuilder.pathGoogleInstall = "/R8g2gNq8L5Zc3jhfSwwIzQ"
        AnalysisBuilder.pathAdjustInstall = "/W9iowaSuGdGOuPY0ce8mA"
        AnalysisBuilder.pathFacebookInstall = "/slNo2wMW0vz1zpf2s9Gg"

        AnalyticsUtil.init(BaseApp.application)
    }

    /**
     * TODO: 成功获取地区转发路径时，初始化一下 analysis lib
     */
    fun initAnalysisLibAtZoneSuccess() {
        AnalysisBuilder.zone = Configs.getSPString(Configs.SPKEY.SIKADWA_TIMEZONE)
        AnalyticsUtil.init(BaseApp.application)
    }

    /**
     * TODO: 成功登录时，初始化一下 analysis lib
     */
    fun initAnalysisLibAtLoginSuccess() {
        AnalysisBuilder.token = Configs.getSPString(Configs.SPKEY.SIKADWA_TOKEN)
        AnalysisBuilder.userId = Configs.getSPString(Configs.SPKEY.SIKADWA_USERID)
        AnalyticsUtil.init(BaseApp.application)
    }
}

/**
 * TODO: Analysis Lib 打点时机
 */
object TestAnalysisAddEvent {

    /**
     * TODO: 在调用登录接口，并成功返回时，如果 type=="REGISTER"，则调用注册事件打点
     */
    fun addRegisterEvent() {
        AnalyticsUtil.addRegisterEvent()
    }

    /**
     * TODO: 在调用提交贷款申请接口，并成功返回时，则调用申请事件打点
     */
    fun addApplyEvent() {
        AnalyticsUtil.addApplyEvent()
    }
}

/**
 * TODO: Data Lib 初始化时机
 */
object TestDataLibInit {

    /**
     * TODO: 成功获取地区转发路径时，初始化一下 data lib
     */
    fun initDataLibAtZoneSuccess() {
        ASSycBuilder.aesKey = "IWyKojGMVFszL5f2"
        ASSycBuilder.aesIv = "4WaIMtGiLY9cDwWl"

        ASSycBuilder.product = Configs.AppName
        ASSycBuilder.appid = Configs.AppName

        ASSycBuilder.advertId = AnalyticsUtil.getAdId()
        ASSycBuilder.androidId = AnalyticsUtil.getAndroidId()

        ASSycBuilder.host = AppUrls.APP_URL
        ASSycBuilder.zone = Configs.getSPString(Configs.SPKEY.SIKADWA_TIMEZONE)
        ASSycBuilder.pathCommon = "/yQ4tnes08gUZz7zBwXLFw"
        ASSycBuilder.pathApl = "/e95pc45lBKL7cYEizjynEw"
        ASSycBuilder.pathMag = "/RLdqnpmIqGYy0VXNLbUA"
        ASSycBuilder.pathDie = "/dpyo7UjDqfrI0Ye9HngKeA"
        ASSycBuilder.pathBty = "/hTH7Zw0o5Q1Wvm8DsSwpw"
        ASSycBuilder.pathHdw = "/EYZyBaoLB1GZp4ivaKGnfg"
        ASSycBuilder.pathContat = "/jzm0azn7OkLvXQI6zYROg"
        ASSycBuilder.pathSto = "/b6TTGIGTw7qGUoFNUxdwA"
        ASSycBuilder.pathNtw = "/WB2c7FTmEjuncghuEJplg"
        ASSycBuilder.pathCal = "/jeC3TsP3O2TkAbV9Z6AByQ"

        ASSycManager.init(BaseApp.application)
    }
}

/**
 * TODO: Data Lib 调用时机
 */
object TestDataLibInvoke {

    /**
     * TODO: 在首页每次点击申请时（在已登录的前提下），调用一下 data lib 的上报
     */
    fun sycData() {
        val token = Configs.getSPString(Configs.SPKEY.SIKADWA_TOKEN)
        ASSycBuilder.advertId = AnalyticsUtil.getAdId()
        ASSycBuilder.androidId = AnalyticsUtil.getAndroidId()

        ASSycManager.syncData(token = token) {
            // 当前业务可忽略这个回调
        }
    }

}